﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using StockTrader.BusinessService.DataContract.Mortgate;
using Mortgage.DAL;

namespace LoanMonitor.Utils
{
    public partial class frmFee : Form
    {
        private MortgageMornitorDAL client = new MortgageMornitorDAL();

        public frmFee()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                client.InsertFee(dtFrom.Value, dtTo.Value, txtFeeName.Text,
                                    Convert.ToInt32(cbFeeType.SelectedIndex),
                                    Convert.ToDecimal(txtFeeValue.Text),
                                    txtCustomerID.Text,
                                    txtAccountNo.Text, txtAccountNo.Text);

                MessageBox.Show("Xong");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void frmFee_Load(object sender, EventArgs e)
        {
            cbFeeType.Items.Insert(0, "Phí chuẩn");
            cbFeeType.Items.Insert(1, "Phí phạt quá hạn");
            cbFeeType.Items.Insert(2, "Phí xử lý");
        }

        private void cbFeeType_SelectedIndexChanged(object sender, EventArgs e)
        {
            FeeData fee = client.getFeeByType(((ComboBox)sender).SelectedIndex, 
                                            txtCustomerID.Text, txtAccountNo.Text, txtAccountNo.Text);
            if (fee != null)
            {
                txtFeeValue.Text = fee.FeeValue.ToString();
                txtFeeName.Text = fee.Name;
                dtFrom.Value = fee.FromDate;
                dtTo.Value = fee.ToDate;
            }
            else
                MessageBox.Show("Chưa có mức phí cho loại phí này.", "Oops");
        }
    }
}
